package test;

import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;
    public MyStack(){
        this.elem=new int[10];
    }
    public boolean isFull() {
        if(usedSize==this.elem.length){
            return true;
        }
        return false;
    }
    public void push(int item) {
        if(isFull()){
            this.elem= Arrays.copyOf(this.elem,2*this.elem.length);
        }
        this.elem[this.usedSize]=item;
        this.usedSize++;
    }
    public boolean empty() {
        return this.usedSize==0;
    }
    public int pop() throws RuntimeException{
        if (empty()){
            throw new RuntimeException("栈空了");
        }
        return this.elem[--this.usedSize];
    }
    public int peek() {
        if (empty()){
            throw new RuntimeException("栈空了");
        }
        return this.elem[this.usedSize-1];
    }
}
